package com.taldh.algorithm.array;

import java.util.HashMap;

public class SingleNumber {

    public int singleNumber(int[] nums) {
        HashMap<Integer, Integer> tmp = new HashMap<>();
        for (int num : nums) {
            if (tmp.containsKey(num)) {
                if (tmp.get(num) == 1) {
                    tmp.put(num, 2);
                } else {
                    tmp.remove(num);
                }
            } else {
                tmp.put(num, 1);
            }
        }
        return tmp.keySet().iterator().next();
    }
}